
package com.liao.badminton.controller;

import com.github.pagehelper.PageInfo;
import com.liao.badminton.code.PageParam;
import com.liao.badminton.code.ProjectException;
import com.liao.badminton.code.ResponseRest;
import com.liao.badminton.code.validation.Delete;
import com.liao.badminton.code.validation.FindDetail;
import com.liao.badminton.code.validation.Insert;
import com.liao.badminton.code.validation.Update;
import com.liao.badminton.dto.BadmintonGroupDto;
import com.liao.badminton.service.BadmintonGroupService;
import com.liao.badminton.vo.BadmintonGroupVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liaocheng
 * @date 2024-11-01
 * description:群表
 */
@RestController
@RequestMapping(value = "/badmintonGroup")
@PreAuthorize("@ss.hasPermission('badmintonGroup')")//权限管理;
public class BadmintonGroupController {

    //  private static  Logger logger= LoggerFactory.getLogger(BadmintonGroupController.class);

    @Resource
    private BadmintonGroupService badmintonGroupService;


    /**
     * 新增badmintonGroup
     */
    @RequestMapping(value = "/add")
    @PreAuthorize("@ss.hasPermission('badmintonGroup:add')")//权限管理;
    public ResponseRest<Long> add(@RequestBody @Validated(Insert.class) BadmintonGroupDto badmintonGroup) throws ProjectException {
        return ResponseRest.suc("saveBadmintonGroup",badmintonGroupService.saveBadmintonGroup(badmintonGroup));
    }

    /**
     * 批量删除
     */
    @RequestMapping(value = "/deletes")
    @PreAuthorize("@ss.hasPermission('badmintonGroup:deletes')")//权限管理;
    public ResponseRest<Boolean> deletes(@RequestBody @Validated(Delete.class) BadmintonGroupDto param) throws ProjectException {
        return badmintonGroupService.deletesBadmintonGroup(param);
    }

    /**
     * 修改badmintonGroup
     */
    @RequestMapping(value = "/update")
    @PreAuthorize("@ss.hasPermission('badmintonGroup:update')")//权限管理;
    public ResponseRest<Boolean> update(@RequestBody @Validated(Update.class) BadmintonGroupDto param) throws ProjectException {
        return badmintonGroupService.updateBadmintonGroup(param);
    }

    @RequestMapping(value = "/findDetail")
    @PreAuthorize("@ss.hasPermission('BadmintonGroup:findDetail')")//权限管理;
    public ResponseRest<BadmintonGroupVo> findDetail(@RequestBody @Validated(FindDetail.class) BadmintonGroupDto param) throws ProjectException {
        return badmintonGroupService.findDetail(param);
    }

    /**
     * 分页查询列表
     */
    @RequestMapping(value = "/list")
    @PreAuthorize("@ss.hasPermission('badmintonGroup:list')")//权限管理;
    public ResponseRest<PageInfo<BadmintonGroupVo>> list(@RequestBody PageParam<BadmintonGroupDto> body) throws ProjectException {
        return badmintonGroupService.findBadmintonGroupByPageParam(body);
    }


    /**
     * 分页查询列表
     */
    @RequestMapping(value = "/getListByUserId")
    @PreAuthorize("@ss.hasPermission('badmintonGroup:getListByUserId')")//权限管理;
    public ResponseRest<PageInfo<BadmintonGroupVo>> getListByUserId(@RequestBody PageParam<BadmintonGroupDto> body) throws ProjectException {
        return badmintonGroupService.getListByUserId(body);
    }
    /**
     * 不分页查询列表
     */
    @RequestMapping(value = "/findGroupByUserId")
    @PreAuthorize("@ss.hasPermission('badmintonGroup:findGroupByUserId')")//权限管理;
    ResponseRest<List<BadmintonGroupVo>> findGroupByUserId(@RequestParam(name = "userId",required = false) Long userId) throws ProjectException {
        return ResponseRest.suc("findGroupByUserId",badmintonGroupService.findGroupByUserId(userId));
    }

}
